package pl.enigmatic.parser.xml;

import java.util.HashMap;
import java.util.Map;

import org.w3c.dom.Element;

import pl.enigmatic.util.Path;


public class StaticParsingInfo extends XMLNSRetriever {

	private final Path path;
	private final Element xml;
	private final Map<ParsingMetadata, Object> metadata;
	private final Map<String, Object> objects = new HashMap<String, Object>();

	public StaticParsingInfo(final Element xml, final Map<ParsingMetadata, Object> metadata, final String filepath) {
		path = new Path(Path.getParentDirectory(filepath));
		this.xml = xml;
		for (final ParsingMetadata key : ParsingMetadata.values()) {
			if (!metadata.containsKey(key)) {
				metadata.put(key, key.getDefaultValue());
			}
		}
		this.metadata = metadata;
	}

	public Element getXML() {
		return xml;
	}

	public boolean addNamedObject(final String name, final Object obj) {
		if (objects.containsKey(name)) { return false; }
		objects.put(name, obj);
		return true;
	}

	public Object getNamedObject(final String name) {
		return objects.get(name);
	}

	public boolean containsNamedObject(final String name) {
		return objects.containsKey(name);
	}

	public Object getMetadata(final ParsingMetadata key) {
		return metadata.get(key);
	}

	public boolean getMetadataBoolean(final ParsingMetadata key) {
		return (Boolean) metadata.get(key);
	}

	public String getMetadataString(final ParsingMetadata key) {
		return (String) metadata.get(key);
	}

	public Path getPath() {
		return path;
	}
}
